package com.example.sqltest.pojo;

import com.example.sqltest.enums.UserStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author: dangwen
 * @createDate: 2020/12/2
 */
@Getter
@Setter
@Entity
@Table(name = "agentuser_log")
public class AgentUserLog implements Serializable {
    private static final long serialVersionUID = 5481899464625926625L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private Integer tenantId; // 租户ID
    @CreationTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date operateTime; // 操作时间
    @Enumerated(EnumType.STRING)
    private UserStatus operateType; // 操作类型
    private String operatorAccount; // 操作人账号
    private String beOperatedAccount; // 被操作人账号

    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "agentUser_id")
    private AgentUser agentUser;

    /**
     *  关联关系中记得重写toString方法覆盖lombok的toString，不然会套娃打印，直到栈溢出
     */
    @Override
    public String toString() {
        return "AgentUserLog{" +
                "id=" + id +
                ", tenantId=" + tenantId +
                ", operateTime=" + operateTime +
                ", operateType=" + operateType +
                ", operatorAccount='" + operatorAccount + '\'' +
                ", beOperatedAccount='" + beOperatedAccount + '\'' +
                '}';
    }
}
